Babyplots Jupyter Notebook Demo

Babyplots is available through the babyplots python package to use in jupyter notebooks to visualize your data.

The babyplots python implementation is still in development, more features like exporting and publishing to the babyplots website are coming soon.

In [2]:
from babyplots import Babyplot
import pandas as pd

Plot Demo

In [3]:
dat = pd.read_csv("E:/Dokumente/repos/mca_dt.txt", sep="\t")
In [4]:
dat.head()
Out[4]:
UMAP_1 UMAP_2 UMAP_3 orig.ident nCount_RNA nFeature_RNA ClusterID Tissue Batch Cell.Barcode percent.mt RNA_snn_res.3 seurat_clusters
0 2.232274 -7.775582 -10.968533 MouseCellAtlas 11512 3469 Bladder_9 Bladder Bladder_1 CCATCTAGCGAGTTTAGG 2.936067 69 69
1 2.092620 -7.915526 -10.998805 MouseCellAtlas 13580 3725 Bladder_9 Bladder Bladder_1 GAGGAGCGCTTGATACAG 2.260677 69 69
2 1.947722 -7.657710 -10.638845 MouseCellAtlas 12089 3401 Bladder_9 Bladder Bladder_1 CCAGACACAATAGAATTA 2.225163 69 69
3 2.109386 -7.830964 -10.924024 MouseCellAtlas 12949 3574 Bladder_9 Bladder Bladder_1 CCGACGGGACATATGGCG 1.814812 69 69
4 2.229176 -7.529998 -10.927272 MouseCellAtlas 11790 3392 Bladder_9 Bladder Bladder_1 TAGCATTCAAAGATTCCA 2.044105 69 69
In [5]:
coords = dat.iloc[:,0:3].values.tolist()
In [6]:
clusts = dat["Tissue"].values.tolist()
In [7]:
bp = Babyplot()
bp.add_plot(coords, "pointCloud", "categories", clusts, {"colorScale": "Paired"})
In [8]:
bp
Out[8]:
In [9]:
bp.width = "768px"
bp.height = "320px"
In [10]:
bp.plots[0]["options"]["colorScale"]  = "Set3"
bp.plots[0]["options"]["showLegend"] = False
bp.plots[0]["options"]["showAxes"] = [True, True, True]
In [11]:
bp
Out[11]:

Image Stack Demo

In [12]:
bp2 = Babyplot(background_color="#000000ff")
bp2.add_tiff("RGB.tif", channel_thresholds=[0.3,0.1, 1], options={"size": 1, "intensityMode": "alpha"})
In [13]:
bp2.plots[0]["attributes"]
Out[13]:
{'dim': [1024, 1024, 3, 98]}
In [14]:
bp2.plots[0]["plot_type"]
Out[14]:
'imageStack'
In [15]:
bp2
Out[15]:

Iris PCA example

In [16]:
import numpy as np
from sklearn import decomposition
from sklearn import datasets
np.random.seed(5)
In [17]:
iris = datasets.load_iris()
X = iris.data
y = iris.target
In [18]:
pca = decomposition.PCA(n_components=3)
pca.fit(X)
X = pca.transform(X)
In [19]:
bp_iris = Babyplot(shape_legend_title="Species", background_color="#00000000")
species = [('Setosa', 0, "red", "box"), ('Versicolor', 1, "green", "cone"), ('Virginica', 2, "blue", "sphere")]
for name, label, color, shape in species:
    X_subset = X[y == label, ]
    bp_iris.add_plot(X_subset.tolist(), "shapeCloud", "direct", [color] * X_subset.shape[0], {"shape": shape, "name": name, "legendShowShape": True})

bp_iris.width = "768px"
bp_iris.height = "320px"
In [20]:
bp_iris
Out[20]:
In [21]:
bp_iris2 = Babyplot(background_color="#262626ff", x_scale=0.6, show_ui=True)
bp_iris2.add_plot(X.tolist(), "shapeCloud", "categories", y.tolist(), {"shape": "sphere", "colorScale": "Set2", "showAxes": [True, True, True], "axisLabels": ["PC 1", "PC 2", "PC 3"]})
In [22]:
bp_iris2
Out[22]:
In [ ]: